package org.example.manage.impl;

import org.example.manage.FirstManage;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Component
 public class FirstManageImpl implements FirstManage {

    @Resource
    private RedisTemplate<String,Object> redisTemplate;
    @Override
    public void insertSet(String key, String value) {
        redisTemplate.opsForValue().set(key,value);
    }

    @Override
    public void insertSet(String key, String value, Long ttl) {
        redisTemplate.opsForValue().setIfAbsent(key,value,ttl, TimeUnit.SECONDS);
    }

    @Override
    public String getSet(String key) {
        return (String)redisTemplate.opsForValue().get(key);

    }

    //插入hash
    @Override
    public void insertHash(String key, String field, String value) {
            redisTemplate.opsForHash().put(key,field,value);
    }

    //hash递增
    @Override
    public void incrHash(String key, String field) {
            redisTemplate.opsForHash().increment(key,field,1);
    }

    @Override
    public void decrHash(String key, String field) {
            redisTemplate.opsForHash().increment(key,field,-1);
    }

    @Override
    public Map<Object, Object> getHash(String key) {
       // redisTemplate.opsForValue().setBit();   bitmap   1010   10
       return redisTemplate.opsForHash().entries(key);
    }

    @Override
    public void insertGeo(String key,double x,double y,String areaName){
        redisTemplate.opsForGeo().add(key,new Point(x,y),areaName);
    }
}
